import {dialog} from "electron";

interface EventSteam{
  event: string
  data: unknown
}
export default function handlerIpc(ipcMain: Electron.IpcMain) {
  ipcMain.on('git-event', (event: Electron.IpcMainInvokeEvent, ...args: EventSteam[]) => {
    const es = args[0]
    event.sender.send(es.event, es.data)
  })

  ipcMain.on('open-dir', (ev) => {
    dialog
      .showOpenDialog({
        properties: ['openDirectory']
      })
      .then((result) => {
        if (!result.canceled) {
          ev.sender.send('open-dir-confirm', result.filePaths[0])
        }
      })
      .catch((err) => {
        console.log(err)
      })
  })
}
